var TableServer = function () {

    var initTable = function(nodeId, module, method, sort) {
        //获取特定的排序列
        var aoColumns = new Array();
        var aaSorting = new Array();
        if(!(sort == null || sort === "undefined")){
        	var totalcol = sort[0];
        	for(var i = 0; i < totalcol; i++){
        		aoColumns.push({"bSortable": false});
        	}
        	for(var i = 0; i < sort[2].length; i++){
        		aoColumns[sort[2][i]].bSortable = true;
        	}
        	aaSorting.push(new Array(sort[1], 'desc'));
        }else{
        	aaSorting.push(new Array(0, 'desc'));
        }
        
        /*
         * Initialse DataTables, with no sorting on the 'details' column
         */
        var oTable = $('#' + nodeId).dataTable( {
        	"aoColumns": aoColumns,
            "aaSorting": aaSorting,//此处也可以设置为输入的
            'bProcessing': true,
            "bServerSide": true,
            "sAjaxSource": hjjp_rootUrl + "/" + module + "/" + method + "json",
            "bStateSave" : true,
            "aLengthMenu": [
                [5, 10, 20, -1],
                [5, 10, 20, "All"] // change per page values here
            ],
            "oLanguage": {
            	"sLengthMenu": "每页显示 _MENU_ 条记录",
				"sZeroRecords": "抱歉， 没有找到相应记录",
				"sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
				"sInfoEmpty": "没有数据",
				"sInfoFiltered": "(从 _MAX_ 条数据中检索)",
				"oPaginate": {
					"sFirst": "首页",
					"sPrevious": "前一页",
					"sNext": "后一页",
					"sLast": "尾页"
				},
            	"sSearch": "搜索:",
            	"sProcessing": "处理中..."
            },
            "sZeroRecords": "没有检索到数据",
            // set the initial value
            "iDisplayLength": 10,
        });

        jQuery('#' + nodeId + '_wrapper .dataTables_filter input').addClass("m-wrap small"); // modify table search input
        jQuery('#' + nodeId + '_wrapper .dataTables_length select').addClass("m-wrap small"); // modify table per page dropdown
        // $('#' + nodeId + '_wrapper .dataTables_filter input').keyup(function(){
        	// oTable.fnFilter(this.value, 1);
        // });
        $("select#type").change(function(){
		     oTable.fnFilter($(this).val(), 3);
		});
    };

    return {

        //main function to initiate the module
        init: function (nodeId, module, method, sort) {
            
            if (!jQuery().dataTable) {
                return;
            }
			
            initTable(nodeId, module, method, sort);
        }

    };

}();